<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>服务站管理</title>
<%@ include file="../../common/importLib.jsp" %>
<link rel="stylesheet" type="text/css" href="../common/css/codeDownload.css">
<script type="text/javascript" src="../common/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="../common/jquery-cascade/js/jquery.cityselect.js"></script>
<!-- <script type="text/javascript" src="js/mrjy.maintain.js"></script>	 -->
<script type="text/javascript">
	/**
	 * 增删改查参数设置
	 */
	
	tableTitle = "服务站表";
	tableURL = getTimeURL("serviceStationInfo/stationList.do");
	toolbarView = 2;
	tableColumns = [[{field:'ck',checkbox:true},
	                {field:'id',title:'id',width:0,rowspan:1},
					{field:'opt',title:'操作',width:130,align:'center', rowspan:1,
						formatter:function(value,rowData,rowIndex){	
							var queryUrl = 'serviceStationInfo/queryById.do?id=' + rowData.id;						
							return "<a title='修改' class='xxl_linkbutton' iconCls='icon-edit' href='javascript:datagridUpdate(\"" + queryUrl + "\")'>修改</a>";
						}
					},	
					{field:'stationName',title:'服务站名称',width:120,rowspan:1},
					{field:'adminLoginCode',title:'管理员账号',width:120,rowspan:1},
					//{field:'adminMobilePhone',title:'管理员联系手机',width:120,rowspan:1},
					//{field:'schoolName',title:'所属学校',width:120,rowspan:1},
					{field:'staionRecommendCode',title:'推荐号',width:80,align:'center',rowspan:1},
					{field:'staionRecommendCode_',title:'推荐二维码',width:80,align:'center', rowspan:1,
						formatter:function(value,rowData,rowIndex){
							if(rowData.staionRecommendCode!=null && rowData.staionRecommendCode!=""){
								var para = "?para="+rowData.staionRecommendCode;
								var codeName = rowData.stationName + "_"+rowData.adminLoginCode;
								return "<a class='xxl_linkbutton saveCode' iconCls='icon-download' href='javascript:openDownWindow(\"http://"+ host + phoneWebUrl +"person/fast_register.html"+ para +"\",\""+ codeName  +"\");'>下载</a>";
							}else{
								return "无";
							}
						}
					},
					{field:'promoteUrl',title:'推广链接',width:150,rowspan:1},
					{field:'stationMobilePhone',title:'服务站手机号码',width:120,rowspan:1},
					{field:'stationTelPhone',title:'服务站固话号码',width:120,rowspan:1},
					{field:'address',title:'服务站地址',width:200,rowspan:1},	
					{field:'stationDesc',title:'服务站简介',width:250,rowspan:1},
					{field:'registerDateString',title:'添加日期',width:150,rowspan:1},
					{field:'sharingProportion',title:'分成比例',width:100,rowspan:1},
					{field:'signTimeString',title:'签订时间',width:150,rowspan:1},
					{field:'deadlineTimeString',title:'截止有效期',width:150,rowspan:1},
					{field:'disableFlag',title:'禁用状态',width:80,align:'center', rowspan:1,
						formatter:function(value,rowData,rowIndex){
							if(rowData.disableFlag == 0){
								return "<font color='green'>起用</font>";
							}else{
								return "<font color='red'>禁用</font>";
							}
						}
					}]];
	
	var addWidth = 700; //添加窗口宽度
	var addHeight = 450; //添加窗口高度
	var addTitle = "添加服务站"; //添加标题
	var updateWidth = 700; //修改窗口宽度
	var updateHeight = 450; //修改窗口高度
	var updateTitle = "修改服务站信息"; //修改标题
	var updateDisableFlagUri = "serviceStationInfo/updateDisableFlag.do"; //禁用、起用记录
	var deleteUri = "serviceStationInfo/deleteByIds.do"; //删除记录
	
	/**
	 * 初始化添加表单
	 */	
	function initAddForm(){
		$("#city_4Add").citySelect({
			prov : "广东",
			city : "广州",
			dist : "天河区",
			nodata : "none" //当子集无数据时，隐藏select
		});
		addFormProcess("stationNameAdd","服务站",true);
		//ajaxFormValidator_conbox("#schoolId","学校",1,"schoolInfo/schoolValidate.do");
		//baseFormValidator("stationNameAdd", "服务站名称", 2, 18, "chinese");
		//baseFormValidator("stationMobilePhoneAdd","电话",11,11,"mobile");
		//ajaxFormValidator("stationNameAdd","服务站名称",2,18,"serviceStationInfo/stationValidate.do",'chinese');
		ajaxFormValidator("adminLoginCodeAdd","管理员账号",1,12,"userInfo/adminLoginCodeValidate.do",'username');
		changeRecommendCode("add");
	}
	
	/**
	 * 初始化修改表单
	 */
	function initUpdateForm(jsonObject){
		//selectRadio(jsonObject.sex,"datagrid_update");
		$("#idUpdate").val(jsonObject.id);
		$("#adminIdUpdate").val(jsonObject.adminId);
		$("#stationNameUpdate").val(jsonObject.stationName);
		$("#staionRecommendCodeUpdate").val(jsonObject.staionRecommendCode);
		$("#stationMobilePhoneUpdate").val(jsonObject.stationMobilePhone);
		$("#stationTelPhoneUpdate").val(jsonObject.stationTelPhone);
		$("#city_4Update").citySelect({prov:jsonObject.province, city:jsonObject.city, dist:jsonObject.county,nodata : "none"});
		$("#streetUpdate").val(jsonObject.street);
		$("#stationDescUpdate").val(jsonObject.stationDesc);
		$("#adminLoginCodeUpdate").val(jsonObject.adminLoginCode);
		$("#adminMobilePhoneUpdate").val(jsonObject.adminMobilePhone);
		updateFormProcess("stationNameUpdate","服务站");
		//ajaxFormValidator("stationNameUpdate","服务站名称",2,18,"serviceStationInfo/stationValidate.do?stid="+jsonObject.id,'chinese');
		baseFormValidator("stationMobilePhoneUpdate", "服务站手机", 11, 11, "mobile");
		//$("#stationMobilePhoneUpdate").trigger("blur");
		ajaxFormValidator("adminLoginCodeUpdate","管理员账号",1,12,"userInfo/adminLoginCodeValidate.do?stid="+jsonObject.adminId,'username');
		$("#stationNameUpdate").trigger("blur");
		$("#stationMobilePhoneUpdate").trigger("blur");
		$("#adminMobilePhoneUpdate").trigger("blur");
		$("#adminLoginCodeUpdate").trigger("blur");
		
		$("#signTimeUpdate").val(jsonObject.signTimeString);
		$("#sharingProportionUpdate").val(jsonObject.sharingProportion);
	}
	
	function ajaxLoading(){ 
	    $("<div class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:600}).appendTo("#datagrid_import");   
	    $("<div class=\"datagrid-mask-msg\"></div>").html("正在处理，请稍候。。。").appendTo("#datagrid_import").css({display:"block",left:(850 - 190) / 2,top:(600 - 45) / 2});   
	 }
	 function ajaxLoadEnd(){
	     $(".datagrid-mask").remove();
	     $(".datagrid-mask-msg").remove();               
	}
	
	 /**
	 *打开二维码下载窗口
	 */
	function openDownWindow(urlStr,codeName){
		var downPage = '<div class="codeDownload">'+
			  	'<div class="codeDownload-content">'+
			  		'<div id="code_download"></div>'+
			  		'<select id="codeSize" name="codeSize" class="form-control select-box">'+
			  			'<option value="256">256×256分辨率</option>'+
			  			'<option value="512">512×512分辨率</option>'+
			  			'<option value="1024">1024×1024分辨率</option>'+
			  		'</select>'+
			  		'<a id="download_btn" class="btn download-btn">下载</a>'+
			  		'<a id="cancel_btn" class="btn cancel-btn">取消</a>'+
			  	'</div>'+
			 '</div>';
		$("body").append(downPage);
		$("#code_download").qrcode(urlStr);
		$("#code_download>canvas").width(150);
		$("#code_download>canvas").height(150);
		$("#download_btn").on('click',function(){
			var size = $("#codeSize").val();
			saveCode(urlStr,size,size,codeName);
		})
		$("#cancel_btn").on('click',function(){
			$(".codeDownload").remove();
		})
	}
	/**
	 * 二维码下载
	 */
	function saveCode(content,width,height,codeName){
		width = width?width:512;
		height = height?height:512;
		$('#code_download').html("").qrcode({
			render:"canvas",
			width: width,
			height:height,
			correctLevel:0,
			text:content
		});
		$("#code_download>canvas").width(150);
		$("#code_download>canvas").height(150);
		var myCanvas = $("#code_download>canvas")[0];
	    var image = myCanvas.toDataURL("image/png").replace("image/png", "image/octet-stream;Content-Disposition: attachment;filename=myCode.png");   
	//  window.location=image; // it will save locally
		var a = document.createElement("a");
		codeName = codeName+"_"+new Date().getTime();
		a.download = codeName + ".jpg";
		a.href = image;
		a.click();
		$(".codeDownload").remove();
	}
	 /**
	 *	更改推荐码
	 */
	function changeRecommendCode(type){
		$.ajax({
			type : "post",
			url:"userInfo/getRecommendCode.do",
			dataType:"json",
			async:true,
			success:function(data){
				if(data){
					if(type==="add"){
						$("#staionRecommendCodeAdd").val(data);
					}else if(type==="update"){
						$("#staionRecommendCodeUpdate").val(data);
					}
				}
			}
		})
	}
	//新增提交方法
	function addFormSubmit(){
		var params = getFormJson($('#add_form'));
		$.ajax({
			  type: 'POST',
			  url: '../maintain/serviceStationInfo/addServiceStation.do',
			  data: params,
			  dataType: 'json',
			  async: false,
			  success: function(data){
				  if(data.err_code ==0){
					  $('#datagrid_add').window('close');
					  $('#datagrid_table').datagrid('reload');
				  }else {
					alert("新增失败！" + data.err_msg);
				  }
			  },
			  error: function(xhr, type){
			    alert('Ajax error!')
			  }
		});
	}
	//更新提交的方法
	function updateFormSubmit(){
		var params = getFormJson($('#update_form'));
		$.ajax({
			  type: 'POST',
			  url: '../maintain/serviceStationInfo/updateServiceStation.do',
			  data: params,
			  dataType: 'json',
			  async: false,
			  success: function(data){
				  if(data.err_code ==0){
					  $('#datagrid_update').window('close');
					  $('#datagrid_table').datagrid('reload');
				  }else {
					alert("更新失败！" + data.err_msg);
				  }
			  },
			  error: function(xhr, type){
			    alert('Ajax error!')
			  }
		});
	}
	//将form中的值转换为键值对。
	function getFormJson(frm) {
	    var o = {};
	    var a = $(frm).serializeArray();
	    $.each(a, function () {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });

	    return o;
	}
</script>
<script type="text/javascript">
$(function(){
	//combobox_5("claId", "../classInfo/selectByClassList.do", true,"");
	//combobox_1("stationName_search", "schoolInfo/schoolList.do",false)
	//createTable();
	$("#city_search").citySelect({prov : "",required:false,nodata : "hidden"});
});
</script>
</head>
	<style>
	#datagrid_add,#datagrid_update{
		padding:  10px 20px;
	}
	
	#datagrid_add tr,#datagrid_update tr{
	    height: 30px;
	}
		
	</style>
<body id="layout" class="easyui-layout">

	<div style="background: none repeat scroll 0% 0% #EFEFEF; height:100px; padding: 6px 2px; border-bottom: 1px solid #CCC;"
		region="north"  split="false" title="条件查询">
	<form  id="searchForm" >
	<table>
		<tr>
			<td>服务站地址：</td>
			<td colspan="5">
				<div id="city_search">
					<select class="prov" name="province" ></select> 
					<select class="city" name="city"></select>
					<select class="dist" name="county"></select>
				</div>
			</td>
		</tr>
		<tr>
			<td>服务站名称：</td><td><input type="text" name="stationName" id="stationName_search"/> </td>					
			<td width="50px;"></td>
			<!--  <td>学校：</td><td><input type="text" name="schoolId" id="schoolId_search"/> </td>
			<td ><a class="easyui-linkbutton" id="search" iconCls="icon-add" onclick="openImport()">批量导入服务站信息</a></td>-->
			<td><a class="easyui-linkbutton" id="search" iconCLs="icon-search"  onclick="searchTable()">搜索</a></td>
			<td><a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('searchForm').reset();">清空</a></td>
			<td width="50px;"></td>
			
		</tr>
	</table>
	</form>
	</div>
	<div region="center">
	<!-- datagrid信息表 -->
	<table id="datagrid_table"></table>
	<!-- 添加记录 -->
	<div id="datagrid_add">
		<form id="add_form" action="serviceStationInfo/addServiceStation.do" method="post">
			<table width="630" class="xxl_tb_1">
				<tbody>	
					<tr>
						<td width="120" class="xxl_td_2">服务站名称：</td>
						<td ><input type="text" id="stationNameAdd" name="stationName" onchange="validateSubmitOnce=true"/></td>
						<td><div id="stationNameAddTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">服务站推荐码：</td>
						<td><input type="text" id="staionRecommendCodeAdd" name="staionRecommendCode" readonly="readonly" style="border: none;"/></td>
						<td>
							<a style="font-size:20px" href="javascript:changeRecommendCode('add');" >
							<span class="l-btn-text"><span class="l-btn-empty pagination-load">&nbsp;&nbsp;</span></span>
							<span style="font-size: 14px; position: relative;top: -4px;color: #000;left: -10px;">更换</span>
							</a>
						</td>
					</tr>
					<tr>
						<td class="xxl_td_2">服务站手机号码：</td>
						<td><input type="text" id="stationMobilePhoneAdd" name="stationMobilePhone" maxlength="11"/></td>
						<td><div id="stationMobilePhoneAddTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">固定电话：</td>
						<td><input type="text" id="stationTelPhoneAdd" name="stationTelPhone"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="xxl_td_2">服务站地址：</td>
						<td ><div id="city_4Add">
								<select class="prov" name="province" id="province"></select> 
								<select class="city" disabled="disabled" name="city" id="city"></select>
								<select class="dist" disabled="disabled" name="county" id="county"></select>
							</div>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="xxl_td_2">街道地址：</td>
						<td><input type="text" id="streetAdd" name="street"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="xxl_td_2">服务站介绍：</td>
						<td><textarea id="stationDescAdd" name="stationDesc" cols="30" ></textarea></td>
						<td><div id="userDescAddTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td width="120" class="xxl_td_2">服务站管理员账号：</td>
						<td ><input type="text" id="adminLoginCodeAdd" name="adminLoginCode" onchange="validateSubmitOnce=true"/></td>
						<td><div id="adminLoginCodeAddTip" style="width:250px"></div></td>
					</tr>
					<!-- 
					<tr>
						<td width="120" class="xxl_td_2">服务站管理员手机：</td>
						<td ><input type="text" id="adminMobilePhoneAdd" name="adminMobilePhone" maxlength="11" onchange="validateSubmitOnce=true"/></td>
						<td><div id="adminMobilePhoneAddTip" style="width:250px"></div></td>
					</tr>
					 -->
					 <tr>
						<td class="xxl_td_2">分成比例：</td>
						<td><input type="text" id="sharingProportion" name="sharingProportion" class="easyui-numberbox" min="0" precision="2" max="1" /></td>
					</tr>
					 <tr>
						<td class="xxl_td_2">合同签订时间：</td>
						<td><input type="text" name="signTimeString" id="signTime" style="width: 150px;" class="input-style" onclick="WdatePicker({el:'signTime', dateFmt: 'yyyy-MM-dd HH:mm:ss'})"/></td>
					</tr>
					<tr>
						<td colspan="3" style="text-align: center">		
							<a class="easyui-linkbutton" iconCls="icon-ok" onclick="addFormSubmit()">添加</a>
							<a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('add_form').reset()">重置</a>
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#datagrid_add').window('close');">取消</a>
						</td>
					</tr>
					<tr>
						<td class="xxl_td_2"></td>
						<td><div style="width:250px;color: red">*服务站管理员的默认密码是：123abc</div></td>
						<td></td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	<!-- 批量添加记录 -->
	<div id="datagrid_import"  style="display: none">
		<form id="import_form" action="/maintain/signUpInfo/batchAddSignUpInfo.do" method="post">
		<img src="../../common/images/Student_step_04.png" width="100%" height="43" id="uploadStatus">
		<input type="hidden" id="fileName" name="fileName" onclick='openFileUpload()'>
		<div id="titleTip" style="width:250px;clear: both;"></div>			
		<div id="messageSpan" style="font-family:微软雅黑;font-size:16px;font-weight:bold;color:#FF3366">${message}</div>
		<div id="first">
			<table width="730" class="xxl_tb_1" align="center">
				<tbody>	
					<tr>
						<td  class="xxl_td_2" width="320">学校名称：</td>
						<td ><input type="text" id="subIdImport" /></td>
					</tr>
					<tr>
						<td class="xxl_td_2">班级：</td>
						<td><input type="text" id="classIdImport" name="classIdImport"/></td>
					</tr>
					<tr>
						<td class="xxl_td_2">文件：</td>
						<td>
							<input id='uploadFileImport' type='file' name='uploadFileImport'/><span id='uploadMessageImport'></span>
						</td>
					</tr>
					<tr>
						<td></td>
						<td><a class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:queryUploadUserInfo()">下一步</a>&nbsp;&nbsp;&nbsp;  <a href="/xxl/common/moxls/student_new.xls" >下载模板</a></td>
					</tr>
				</tbody>
			</table>
	    </div>
	    <div id="second" style="display:none">
			<table width="730" id="userInfoList" class="xxl_tb_1" align="center" cellspacing=0 cellpadding=0 border='1' align='center' style="text-align: center; font-family:'宋体'">
			
			</table>
			<div style="text-align: center;">
				<a id="secondSave" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:submitForm()">录入</a>
				<a class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:reUpload()">重新上传</a>
			</div>
	    </div>
	     <div id="three" style="display:none">
			<table width="730" id="userList" class="xxl_tb_1" align="center" cellspacing=0 cellpadding=0 border='1' align='center' style="text-align: center; font-family:'宋体'">
			
			</table>
			<div style="text-align: center;">
				<a class="easyui-linkbutton" iconCls="icon-ok" onclick="exportExcl()">导出学生名单</a>
			</div>
	    </div>
	    </form>
	</div>
	<!-- 修改记录 -->
	<div id="datagrid_update">
		<form id="update_form" action="serviceStationInfo/updateServiceStation.do" method="post">
			<input type="hidden" id="idUpdate" name="id"/>
			<input type="hidden" id="adminIdUpdate" name="adminId">
			<table width="630" class="xxl_tb_1">
				<tbody>
					<tr>
						<td width="120" class="xxl_td_2">服务站名称：</td>
						<td ><input type="text" id="stationNameUpdate" name="stationName" onblur="validateSubmitOnce=true"/></td>
						<td><div id="stationNameUpdateTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">服务站推荐码：</td>
						<td><input type="text" id="staionRecommendCodeUpdate" name="staionRecommendCode" readonly="readonly" style="border: none;"/></td>
						<!-- <td>
							<a style="font-size:20px" href="javascript:changeRecommendCode('update');" >
							<span class="l-btn-text"><span class="l-btn-empty pagination-load">&nbsp;&nbsp;</span></span>
							<span style="font-size: 14px; position: relative;top: -4px;color: #000;left: -10px;">更换</span>
							</a>
						</td> -->
					</tr>
					<tr>
						<td class="xxl_td_2">手机号码：</td>
						<td><input type="text" id="stationMobilePhoneUpdate" name="stationMobilePhone" maxlength="11"/></td>
						<td><div id="stationMobilePhoneUpdateTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">固定电话：</td>
						<td><input type="text" id="stationTelPhoneUpdate" name="stationTelPhone"/></td>
						<td></td>
					</tr>
					<tr>
						<td  class="xxl_td_2">服务站地址：</td>
						<td ><div id="city_4Update">
								<select class="prov" name="province" id="province"></select> 
								<select class="city" name="city" id="city"></select>
								<select class="dist" name="county" id="county"></select>
							</div>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="xxl_td_2">街道地址：</td>
						<td><input type="text" id="streetUpdate" name="street"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="xxl_td_2">服务站介绍：</td>
						<td><textarea id="stationDescUpdate" name="stationDesc" cols="30" ></textarea></td>
						<td><div id="userDescUpdateTip" style="width:250px"></div></td>
					</tr>
					<tr>
						<td width="120" class="xxl_td_2">服务站管理员账号：</td>
						<td ><input type="text" id="adminLoginCodeUpdate" name="adminLoginCode" onblur="validateSubmitOnce=true" /></td>
						<td><div id="adminLoginCodeUpdateTip" style="width:250px"></div></td>
					</tr>
					<!-- 
					<tr>
						<td width="120" class="xxl_td_2">服务站管理员手机：</td>
						<td ><input type="text" id="adminMobilePhoneUpdate" name="adminMobilePhone" maxlength="11" onblur="validateSubmitOnce=true"/></td>
						<td><div id="adminMobilePhoneUpdateTip" style="width:250px"></div></td>
					</tr>
					 -->
					 <tr>
						<td class="xxl_td_2">分成比例：</td>
						<td><input type="text" id="sharingProportionUpdate" name="sharingProportion" class="easyui-numberbox" min="0" precision="2" max="1" /></td>
					</tr>
					 <tr>
						<td class="xxl_td_2">合同签订时间：</td>
						<td><input type="text" name="signTimeString" id="signTimeUpdate" style="width: 150px;" class="input-style" onclick="WdatePicker({el:'signTimeUpdate', dateFmt: 'yyyy-MM-dd HH:mm:ss'})"/></td>
					</tr>
					<tr>
						<td colspan="3" style="text-align: center">
							<a class="easyui-linkbutton" iconCls="icon-ok" onclick="updateFormSubmit();">修改</a>		
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#datagrid_update').window('close');">取消</a>
						</td>
					</tr>
					<tr>
						<td class="xxl_td_2"></td>
						<td><div style="width:250px;color: red">*服务站管理员的默认密码是：123abc</div></td>
						<td></td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	</div>
</body>
</html>